<template>
  <div class="learning-interface">
    <!-- 学习进度指示器 -->
    <div v-if="learningMode === 'detailed'" class="progress-section">
      <div class="progress-header">
        <div class="progress-info">
          <button class="back-btn" @click="handleGoBack">
            <span class="back-icon">←</span>
            返回
          </button>
          <h2 class="progress-title">
            <span class="title-icon">📚</span>
            学习进度
          </h2>
          <div class="learning-path">
            <span class="path-item">{{ selectedCategory?.name }}</span>
            <span class="path-separator">></span>
            <span class="path-item">{{ selectedSubCategory?.name }}</span>
          </div>
        </div>
        <div class="progress-stats">
          <div class="stat-card">
            <span class="stat-number">{{ currentQuestionIndex + 1 }}</span>
            <span class="stat-label">当前题目</span>
          </div>
          <div class="stat-card">
            <span class="stat-number">{{ totalQuestions }}</span>
            <span class="stat-label">总题目</span>
          </div>
          <!-- 考试模式倒计时 -->
          <div
            v-if="examTimeRemaining !== null"
            class="stat-card exam-timer"
          >
            <span
              class="stat-number"
              :class="{ 'time-warning': examTimeRemaining < 5 * 60 * 1000 }"
            >
              {{ formatTime(examTimeRemaining) }}
            </span>
            <span class="stat-label">剩余时间</span>
          </div>
        </div>
      </div>
      <div class="progress-bar-container">
        <div class="progress-bar">
          <div
            class="progress-fill"
            :style="{ width: progressPercentage + '%' }"
          ></div>
        </div>
        <span class="progress-text"
          >{{ Math.round(progressPercentage) }}%</span
        >
      </div>
    </div>



    <!-- 题目卡片 -->
    <div v-if="!isFinished && q" class="question-section">
      <div class="glass-card question-card">
        <div class="question-header">
          <div
            class="question-type-badge"
            :class="getQuestionTypeClass(q.type)"
          >
            {{ getQuestionTypeText(q.type) }}
          </div>
          <div v-if="learningMode === 'detailed'" class="question-number">
            第 {{ currentQuestionIndex + 1 }} 题
          </div>
        </div>

        <div class="question-content">
          <h3 class="question-concept">{{ q.concept }}</h3>
          <p class="question-text">{{ q.title }}</p>

          <!-- 模式切换按钮：编写答案 / 查看答案 / 下一题 -->
          <div class="mode-buttons">
            <button class="mode-btn" @click="startWrite">📝 编写答案</button>
            <button class="mode-btn" @click="viewAnswer">👀 查看答案</button>
            <button class="mode-btn primary" @click="nextQuestion">➡️ 下一题</button>
          </div>

          <!-- 选择题 -->
          <div v-if="uiMode === 'write' && (q.type === 'single_choice' || q.type === 'multiple_choice')" class="options-container">
            <div
              v-for="(option, index) in q.options"
              :key="option"
              class="option-item"
              :class="{ selected: answer === option, disabled: showFeedback }"
              @click="!showFeedback && selectOption(option)"
            >
              <div class="option-marker">
                {{ String.fromCharCode(65 + index) }}
              </div>
              <div class="option-content">{{ option }}</div>
              <div class="option-icon" v-if="showFeedback">
                <span v-if="option === q.answer" class="correct-icon"
                  >✅</span
                >
                <span
                  v-else-if="option === answer && answer !== q.answer"
                  class="incorrect-icon"
                  >❌</span
                >
              </div>
            </div>
          </div>

          <!-- 判断题 -->
          <div v-if="uiMode === 'write' && q.type === 'boolean'" class="boolean-container">
            <div
              v-for="option in booleanOptions"
              :key="option.value"
              class="boolean-option"
              :class="{
                selected: answer === option.value,
                disabled: showFeedback,
              }"
              @click="!showFeedback && selectOption(option.value)"
            >
              <div class="boolean-icon">{{ option.icon }}</div>
              <div class="boolean-text">{{ option.label }}</div>
              <div class="option-icon" v-if="showFeedback">
                <span v-if="String(option.value) === String(q.answer)" class="correct-icon"
                  >✅</span
                >
                <span
                  v-else-if="String(option.value) === String(answer) && String(answer) !== String(q.answer)"
                  class="incorrect-icon"
                  >❌</span
                >
              </div>
            </div>
          </div>

          <!-- 填空题 -->
          <div v-if="uiMode === 'write' && q.type === 'fill'" class="fill-container">
            <div class="input-wrapper">
              <input
                v-model="answer"
                type="text"
                class="fill-input"
                placeholder="请输入答案"
                :disabled="showFeedback"
              />
            </div>
          </div>

          <!-- 代码题 -->
          <div v-if="uiMode === 'write' && q.type === 'code'" class="code-container">
            <div class="code-editor">
              <textarea
                v-model="answer"
                class="code-textarea"
                placeholder="请输入代码"
                :disabled="showFeedback"
                rows="6"
              ></textarea>
            </div>
          </div>

          <!-- 简答题 -->
          <div v-if="uiMode === 'write' && q.questionTypeCode === 'short_answer'" class="short-answer-container">
            <div class="answer-area">
              <div class="answer-header">
                <span class="answer-label">📝 请在此处输入您的答案：</span>
                <span class="word-count">{{ answer.length }}/500</span>
              </div>
              <textarea
                v-model="answer"
                class="answer-textarea"
                placeholder="请详细描述您的答案，建议包含关键概念、步骤说明或相关示例..."
                :disabled="showFeedback"
                rows="8"
                maxlength="500"
              ></textarea>
            </div>
          </div>
        </div>

        <!-- 提交按钮：仅在编写答案模式显示 -->
        <div class="action-buttons" v-if="uiMode === 'write'">
          <button
            class="submit-btn"
            :class="{ disabled: !answer || !answer.trim() }"
            :disabled="!answer || !answer.trim()"
            @click="submit"
          >
            <span class="btn-icon">📝</span>
            {{ q.type === 'short_answer' ? '提交简答' : '提交答案' }}
          </button>
        </div>

        <!-- 查看答案模式下，仅展示正确答案 -->
        <div v-if="uiMode === 'view'" class="feedback-section">
          <div class="feedback-content">
            <div class="correct-answer">
              <span class="label">正确答案：</span>
              <span class="answer">{{ q.answer }}</span>
            </div>
          </div>
        </div>
      </div>

      <!-- 结束学习确认对话框 -->
      <div v-if="showFinishConfirm" class="finish-confirm-overlay">
        <div class="finish-confirm-dialog">
          <div class="confirm-header">
            <div class="confirm-icon">🎯</div>
            <h3 class="confirm-title">学习结束确认</h3>
          </div>
          <div class="confirm-content">
            <p>当前分类下没有更多推荐题目了，是否要结束本次学习？</p>
            <div class="confirm-stats">
              <div class="confirm-stat">
                <span class="stat-label">已答题数：</span>
                <span class="stat-value">{{ recommendTotalQuestions }}</span>
              </div>
              <div class="confirm-stat">
                <span class="stat-label">正确率：</span>
                <span class="stat-value">{{ accuracyRate }}%</span>
              </div>
            </div>
          </div>
          <div class="confirm-actions">
            <button class="secondary-btn" @click="cancelFinishLearning">
              <span class="btn-icon">↩️</span>
              继续学习
            </button>
            <button class="primary-btn" @click="confirmFinishLearning">
              <span class="btn-icon">✅</span>
              确认结束
            </button>
          </div>
        </div>
      </div>
    </div>

    <!-- 完成页面 -->
    <div v-else class="completion-section">
      <div class="glass-card completion-card">
        <div class="completion-header">
                  <div class="completion-icon">🎓</div>
        <h2 class="completion-title">学习完成！</h2>
        <p class="completion-subtitle">恭喜你完成了本次学习任务</p>
        </div>

        <div v-if="learningMode === 'detailed'" class="completion-stats">
          <div class="stat-card">
            <div class="stat-icon">📊</div>
            <div class="stat-content">
              <div class="stat-value">{{ totalQuestions }}</div>
              <div class="stat-label">总题目</div>
            </div>
          </div>
          <div class="stat-card">
            <div class="stat-icon">✅</div>
            <div class="stat-content">
              <div class="stat-value">{{ correctAnswers }}</div>
              <div class="stat-label">正确题目</div>
            </div>
          </div>
          <div class="stat-card">
            <div class="stat-icon">📈</div>
            <div class="stat-content">
              <div class="stat-value">{{ accuracyRate }}%</div>
              <div class="stat-label">正确率</div>
            </div>
          </div>
        </div>



        <div class="completion-actions">
          <button v-if="learningMode === 'detailed'" class="primary-btn" @click="$router.push('/report')">
            <span class="btn-icon">📋</span>
            查看详细报告
          </button>

          <button class="secondary-btn" @click="$emit('restart')">
            <span class="btn-icon">🔄</span>
            重新开始
          </button>
        </div>
      </div>
    </div>
  </div>
</template>

<script>


export default {
  name: "QuestionInterface",
  props: {
    examTimeRemaining: {
      type: Number,
      default: null
    }
  },
  data() {
    return {
      answer: "",
      uiMode: "none", // none | write | view
      showFeedback: false,
      correct: false,
      booleanOptions: [
        { value: "true", label: "正确", icon: "✅" },
        { value: "false", label: "错误", icon: "❌" },
      ],
      // 智能推荐模式相关状态
      loading: false, // 加载状态
      recommendSessionId: null, // 智能推荐会话ID
      showFinishConfirm: false, // 显示结束学习确认对话框
      // 从路由参数获取信息
      categoryId: this.$route.params.categoryId,
      subCategoryId: this.$route.params.subCategoryId,
      studyModeId: this.$route.params.studyModeId,
      questionTypeId: this.$route.params.questionTypeId,
      // 从查询参数获取信息
      limit: this.$route.query.limit || 10,
      mode: this.$route.query.mode || 'detailed'
    }
  },
  computed: {
    q() {
      return this.$store.getters.currentQuestion;
    },
    isFinished() {
      return this.$store.getters.isFinished;
    },
    currentQuestionIndex() {
      return this.$store.state.currentQuestionIndex || 0;
    },
    totalQuestions() {
      return this.$store.state.questions?.length || 0;
    },
    progressPercentage() {
      return this.totalQuestions
        ? ((this.currentQuestionIndex + 1) / this.totalQuestions) * 100
        : 0;
    },
    correctAnswers() {
      return this.$store.getters.score || 0;
    },
    accuracyRate() {
      return this.totalQuestions
        ? Math.round((this.correctAnswers / this.totalQuestions) * 100)
        : 0;
    },
    isLastQuestion() {
      return this.currentQuestionIndex === this.totalQuestions - 1;
    },
    // 从路由参数获取分类信息
    selectedCategory() {
      return {
        id: this.categoryId,
        name: this.$route.params.categoryName || '未知分类'
      };
    },
    selectedSubCategory() {
      return {
        id: this.subCategoryId,
        name: this.$route.params.subCategoryName || '未知子分类'
      };
    },
    learningMode() {
      return this.mode;
    }
  },
  async mounted() {
    // 如果还没有题目数据，则获取题目
    if (!this.$store.state.questions || this.$store.state.questions.length === 0) {
      await this.initializeQuestions();
    }
  },
  methods: {
    startWrite() {
      this.uiMode = "write";
    },
    viewAnswer() {
      this.uiMode = "view";
    },
    // 初始化题目数据
    async initializeQuestions() {
      try {
        this.loading = true;
        
        // 调用开始练习接口获取题目列表
        const { startPractice } = await import('@/api/question');
        const response = await startPractice({
          categoryId: this.categoryId,
          studyModeId: this.studyModeId,
          questionTypeId: this.questionTypeId,
          limit: this.limit,
        });

        // 检查响应数据的有效性
        if (!response || !response.data || !Array.isArray(response.data)) {
          this.$message.error('获取题目失败，请稍后重试');
          return;
        }

        if (response.data.length === 0) {
          this.$message.error('暂无可用的题目，请尝试其他设置');
          return;
        }

        // 将获取到的题目数据存储到 store 中
        this.$store.commit("setQuestions", response.data);
        
        // 根据选择的分类、模式和题型初始化题目
        this.$store.commit("initializeQuestions", {
          category: this.selectedCategory,
          subCategory: this.selectedSubCategory,
          studyModeId: this.studyModeId,
          questionTypeId: this.questionTypeId,
        });

        // 如果是考试模式，启动倒计时
        if (this.studyModeId === "exam") {
          this.$nextTick(() => {
            this.startExamTimer();
          });
        }
      } catch (error) {
        console.error('获取题目列表失败:', error);
        this.$message.error('获取题目失败，请稍后重试');
      } finally {
        this.loading = false;
      }
    },

    // 启动考试倒计时
    startExamTimer() {
      // 这里可以添加考试倒计时逻辑
    },

    // 返回按钮点击事件
    handleGoBack() {
      // 返回到答题模式选择页面
      this.$router.push({
        name: 'learn-question-mode',
        params: {
          categoryId: this.categoryId,
          subCategoryId: this.subCategoryId
        }
      });
    },

    selectOption(option) {
      this.answer = option;
    },

    getQuestionTypeClass(type) {
      const classes = {
        all: "type-all",
        single_choice: "type-choice",
        multiple_choice: "type-choice",
        boolean: "type-boolean",
        fill: "type-fill",
        code: "type-code",
        sort: "type-sort",
        match: "type-match",
        short_answer: "type-short-answer",
        case: "type-case",
      };
      return classes[type] || "type-default";
    },

    getQuestionTypeText(type) {
      const texts = {
        all: "全部题型",
        single_choice: "单选题",
        multiple_choice: "多选题",
        boolean: "判断题",
        fill: "填空题",
        code: "编程题",
        sort: "排序题",
        match: "匹配题",
        short_answer: "简答题",
        case: "案例题",
      };
      return texts[type] || "题目";
    },

    async submit() {
      if (!this.q) return;
      
      // 判断正确性（根据不同的题型进行判断）
      if (this.q.type === "code") {
        // 编程题这里简单用包含判断，后续可接评测服务
        this.correct = this.answer.includes(this.q.answer);
      } else if (this.q.type === "boolean") {
        // 判断题需要特殊处理，确保字符串比较
        this.correct = String(this.answer) === String(this.q.answer);
      } else if (this.q.type === "single_choice" || this.q.type === "multiple_choice") {
        // 单选题和多选题
        this.correct = this.answer === this.q.answer;
      } else if (this.q.type === "fill") {
        // 填空题
        this.correct = this.answer === this.q.answer;
      } else if (this.q.type === "sort") {
        // 排序题
        this.correct = this.answer === this.q.answer;
      } else if (this.q.type === "match") {
        // 匹配题
        this.correct = this.answer === this.q.answer;
      } else if (this.q.type === "short_answer" || this.q.type === "case") {
        // 简答题和案例题 - 使用更智能的评分方式
        this.correct = this.evaluateShortAnswer(this.answer, this.q.answer);
      } else {
        // 其他题型
        this.correct = this.answer === this.q.answer;
      }
      
      this.showFeedback = true;
      

    },

    async nextQuestion() {
      // 详细模式下，保存当前答案并跳转到下一题
      this.$store.commit("nextQuestion", {
        qid: this.q.id,
        answer: this.answer,
        correct: this.correct,
      });
      this.answer = "";
      this.showFeedback = false;
      this.uiMode = "none";
      this.correct = false;
    },



    // 格式化时间显示
    formatTime(milliseconds) {
      const minutes = Math.floor(milliseconds / 60000);
      const seconds = Math.floor((milliseconds % 60000) / 1000);
      return `${minutes.toString().padStart(2, "0")}:${seconds
        .toString()
        .padStart(2, "0")}`;
    },

    evaluateShortAnswer(userAnswer, correctAnswer) {
      if (!userAnswer || !correctAnswer) return false;
      
      // 转换为小写进行比较
      const user = userAnswer.toLowerCase().trim();
      const correct = correctAnswer.toLowerCase().trim();
      
      // 完全匹配
      if (user === correct) return true;
      
      // 关键词匹配 - 检查是否包含关键概念
      const keywords = correct.split(/[，,。.！!？?；;]/).filter(word => word.trim().length > 1);
      const matchedKeywords = keywords.filter(keyword => user.includes(keyword.trim()));
      
      // 如果匹配的关键词超过60%，认为答案正确
      if (keywords.length > 0 && matchedKeywords.length / keywords.length >= 0.6) {
        return true;
      }
      
      // 长度检查 - 如果用户答案太短，可能不够详细
      if (user.length < 10) return false;
      
      // 语义相似度检查（简单版本）
      const userWords = user.split(/\s+/);
      const correctWords = correct.split(/\s+/);
      const commonWords = userWords.filter(word => correctWords.includes(word));
      
      // 如果有足够的共同词汇，认为答案正确
      if (commonWords.length >= Math.min(userWords.length, correctWords.length) * 0.4) {
        return true;
      }
      
      return false;
    },

    

    // 初始化智能推荐模式
    async initRecommendMode() {
      try {
        this.loading = true;
        
        // 生成会话ID
        const sessionId = 'recommend_' + Date.now() + '_' + Math.random().toString(36).substr(2, 9);
        this.recommendSessionId = sessionId;
        
        // 设置智能推荐模式
        this.$store.commit('setSmartRecommendMode', { 
          enabled: true, 
          sessionId: sessionId 
        });
        
        // 获取第一道题目
        await this.getRecommandQuestion();
      } catch (error) {
        console.error('初始化智能推荐模式失败:', error);
        this.$message.error('初始化失败，请稍后重试');
      } finally {
        this.loading = false;
      }
    }
  }
};
</script>

<style scoped>
/* 学习界面 */
.learning-interface {
  max-width: 900px;
  margin: 0 auto;
}

/* 进度指示器 */
.progress-section {
  background: white;
  border-radius: 20px;
  padding: 30px;
  box-shadow: 0 8px 25px rgba(0, 0, 0, 0.1);
  border: 1px solid rgba(0, 0, 0, 0.05);
  margin-bottom: 30px;
}

.progress-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
  flex-wrap: wrap;
  gap: 15px;
}

.progress-info {
  text-align: left;
}

/* 返回按钮样式 */
.back-btn {
  background: #f8fafc;
  border: 2px solid #e2e8f0;
  color: #64748b;
  padding: 10px 16px;
  border-radius: 10px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.3s ease;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 15px;
}

.back-btn:hover {
  background: #e2e8f0;
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

.back-icon {
  font-size: 16px;
  font-weight: bold;
}

.progress-title {
  font-size: 1.5rem;
  color: #2c3e50;
  margin: 0;
  display: flex;
  align-items: center;
  gap: 10px;
}

.title-icon {
  font-size: 1.8rem;
}

.learning-path {
  font-size: 0.9rem;
  color: #7f8c8d;
  margin-top: 5px;
}

.path-item {
  font-weight: 500;
  color: #3b82f6;
}

.path-separator {
  margin: 0 5px;
}

.progress-stats {
  display: flex;
  gap: 20px;
  flex-wrap: wrap;
}

.stat-card {
  background: linear-gradient(135deg, #f8f9fa 0%, #e9ecef 100%);
  border-radius: 15px;
  padding: 15px 20px;
  text-align: center;
  border: 1px solid rgba(0, 0, 0, 0.05);
  min-width: 80px;
}

.stat-number {
  display: block;
  font-size: 1.5rem;
  font-weight: 700;
  color: #3b82f6;
}

.stat-label {
  font-size: 0.8rem;
  color: #7f8c8d;
  margin-top: 5px;
}

.exam-timer .stat-number {
  color: #3b82f6;
  font-weight: 700;
}

.exam-timer .stat-number.time-warning {
  color: #e74c3c;
  animation: pulse 1s infinite;
}

@keyframes pulse {
  0%,
  100% {
    opacity: 1;
  }
  50% {
    opacity: 0.7;
  }
}

.progress-bar-container {
  display: flex;
  align-items: center;
  gap: 15px;
}

.progress-bar {
  flex: 1;
  height: 8px;
  background: #e9ecef;
  border-radius: 4px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, #3b82f6 0%, #1e3a8a 100%);
  transition: width 0.8s cubic-bezier(0.4, 0, 0.2, 1);
  position: relative;
  overflow: hidden;
}

.progress-fill::after {
  content: '';
  position: absolute;
  top: 0;
  left: -100%;
  width: 100%;
  height: 100%;
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.3), transparent);
  animation: shimmer 2s infinite;
}

@keyframes shimmer {
  0% { left: -100%; }
  100% { left: 100%; }
}

.progress-text {
  font-size: 0.9rem;
  color: #3b82f6;
  font-weight: 600;
  min-width: 40px;
}

/* 题目区域 */
.question-section {
  position: relative;
  z-index: 1;
}

.question-card {
  margin: 0 auto;
  animation: slideInUp 0.6s ease-out;
}

@keyframes slideInUp {
  from {
    opacity: 0;
    transform: translateY(30px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.question-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 25px;
}

.question-type-badge {
  padding: 6px 12px;
  border-radius: 20px;
  font-size: 0.8rem;
  font-weight: 600;
  color: white;
}

.type-choice {
  background: linear-gradient(135deg, #1e3a8a 0%, #3b82f6 100%);
}

.type-all {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
}

.type-boolean {
  background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
}

.type-fill {
  background: linear-gradient(135deg, #4facfe 0%, #00f2fe 100%);
}

.type-code {
  background: linear-gradient(135deg, #43e97b 0%, #38f9d7 100%);
}

.type-sort {
  background: linear-gradient(135deg, #fa709a 0%, #fee140 100%);
}

.type-match {
  background: linear-gradient(135deg, #a8edea 0%, #fed6e3 100%);
}

.type-short-answer {
  background: linear-gradient(135deg, #ffecd2 0%, #fcb69f 100%);
}

.type-case {
  background: linear-gradient(135deg, #ff9a9e 0%, #fecfef 100%);
}

.question-number {
  font-size: 0.9rem;
  color: #7f8c8d;
  font-weight: 500;
}

.question-content {
  margin-bottom: 30px;
}

.question-concept {
  font-size: 1.3rem;
  color: #2c3e50;
  margin: 0 0 15px 0;
  font-weight: 600;
}

.question-text {
  font-size: 1.1rem;
  color: #34495e;
  line-height: 1.6;
  margin: 0 0 25px 0;
}

/* 选项样式 */
.options-container {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.option-item {
  display: flex;
  align-items: center;
  padding: 15px 20px;
  border: 2px solid #e9ecef;
  border-radius: 12px;
  cursor: pointer;
  transition: all 0.3s ease;
  position: relative;
}

.option-item:hover:not(.disabled) {
  border-color: #3b82f6;
  background: rgba(59, 130, 246, 0.05);
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(59, 130, 246, 0.15);
}

.option-item:active:not(.disabled) {
  transform: translateY(0px);
}

.option-item.selected {
  border-color: #3b82f6;
  background: rgba(59, 130, 246, 0.1);
  box-shadow: 0 4px 15px rgba(59, 130, 246, 0.2);
}

.option-item.disabled {
  cursor: not-allowed;
  opacity: 0.8;
}

.option-marker {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: #3b82f6;
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  margin-right: 15px;
  flex-shrink: 0;
}

.option-content {
  flex: 1;
  font-size: 1rem;
  color: #2c3e50;
  line-height: 1.4;
}

.option-icon {
  margin-left: 10px;
}

.correct-icon {
  font-size: 1.2rem;
}

.incorrect-icon {
  font-size: 1.2rem;
}

/* 判断题样式 */
.boolean-container {
  display: flex;
  gap: 20px;
}

.boolean-option {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 20px;
  border: 2px solid #e9ecef;
  border-radius: 12px;
  cursor: pointer;
  transition: all 0.3s ease;
}

.boolean-option:hover:not(.disabled) {
  border-color: #3b82f6;
  background: rgba(59, 130, 246, 0.05);
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(59, 130, 246, 0.15);
}

.boolean-option:active:not(.disabled) {
  transform: translateY(0px);
}

.boolean-option.selected {
  border-color: #3b82f6;
  background: rgba(59, 130, 246, 0.1);
  box-shadow: 0 4px 15px rgba(59, 130, 246, 0.2);
}

.boolean-icon {
  font-size: 2rem;
  margin-bottom: 10px;
}

.boolean-text {
  font-size: 1rem;
  color: #2c3e50;
  font-weight: 500;
}

/* 填空题样式 */
.fill-container {
  margin-top: 20px;
}

.input-wrapper {
  position: relative;
}

.fill-input {
  width: 100%;
  padding: 15px 20px;
  border: 2px solid #e9ecef;
  border-radius: 12px;
  font-size: 1rem;
  color: #2c3e50;
  background: white;
  transition: all 0.3s ease;
}

.fill-input:focus {
  outline: none;
  border-color: #3b82f6;
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
  transform: translateY(-1px);
}

.fill-input:disabled {
  background: #f8f9fa;
  cursor: not-allowed;
}

/* 代码题样式 */
.code-container {
  margin-top: 20px;
}

.code-editor {
  border: 2px solid #e9ecef;
  border-radius: 12px;
  overflow: hidden;
  background: #f8f9fa;
}

.code-textarea {
  width: 100%;
  padding: 20px;
  border: none;
  background: transparent;
  font-family: "Monaco", "Menlo", "Ubuntu Mono", monospace;
  font-size: 0.9rem;
  line-height: 1.5;
  color: #2c3e50;
  resize: vertical;
}

.code-textarea:focus {
  outline: none;
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

.code-textarea:disabled {
  cursor: not-allowed;
}

/* 简答题样式 */
.short-answer-container {
  margin-top: 20px;
}

.answer-area {
  border: 2px solid #e9ecef;
  border-radius: 12px;
  background: white;
  overflow: hidden;
  transition: all 0.3s ease;
}

.answer-area:focus-within {
  border-color: #3b82f6;
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
  transform: translateY(-1px);
}

.answer-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 15px 20px;
  background: linear-gradient(135deg, #f8f9fa 0%, #e9ecef 100%);
  border-bottom: 1px solid #e9ecef;
}

.answer-label {
  font-size: 0.95rem;
  color: #2c3e50;
  font-weight: 500;
}

.word-count {
  font-size: 0.8rem;
  color: #7f8c8d;
  font-weight: 500;
  padding: 4px 8px;
  background: white;
  border-radius: 12px;
  border: 1px solid #e9ecef;
}

.answer-textarea {
  width: 100%;
  padding: 20px;
  border: none;
  background: transparent;
  font-family: "Inter", "Segoe UI", "Roboto", sans-serif;
  font-size: 1rem;
  line-height: 1.6;
  color: #2c3e50;
  resize: vertical;
  min-height: 200px;
}

.answer-textarea:focus {
  outline: none;
}

.answer-textarea:disabled {
  cursor: not-allowed;
  background: #f8f9fa;
}

.answer-textarea::placeholder {
  color: #bdc3c7;
  font-style: italic;
}


/* 按钮样式 */
.action-buttons {
  text-align: center;
}

 

.mode-buttons {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin: 10px 0 20px;
  justify-content: center;
}

.mode-btn {
  padding: 10px 18px;
  border-radius: 10px;
  border: 2px solid #e2e8f0;
  background: #f8fafc;
  color: #2c3e50;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
}

.mode-btn:hover {
  background: #e2e8f0;
  transform: translateY(-1px);
}

.mode-btn.primary {
  background: linear-gradient(135deg, #1e3a8a 0%, #3b82f6 100%);
  color: #fff;
  border: none;
}

.mode-btn.primary:hover {
  box-shadow: 0 8px 20px rgba(30, 58, 138, 0.25);
}

.submit-btn {
  padding: 15px 40px;
  border: none;
  border-radius: 25px;
  font-size: 1.1rem;
  font-weight: 600;
  background: linear-gradient(135deg, #1e3a8a 0%, #3b82f6 100%);
  color: white;
  cursor: pointer;
  transition: all 0.3s ease;
  display: inline-flex;
  align-items: center;
  gap: 10px;
}

.submit-btn:hover:not(.disabled) {
  transform: translateY(-2px);
  box-shadow: 0 10px 25px rgba(30, 58, 138, 0.4);
}

.submit-btn.disabled {
  opacity: 0.6;
  cursor: not-allowed;
  transform: none;
}

.btn-icon {
  font-size: 1.1rem;
}

/* 反馈区域 */
.feedback-section {
  margin-top: 30px;
  padding: 25px;
  border-radius: 15px;
  background: linear-gradient(135deg, #f8f9fa 0%, #e9ecef 100%);
  border: 1px solid rgba(0, 0, 0, 0.05);
  animation: slideInDown 0.5s ease-out;
}

@keyframes slideInDown {
  from {
    opacity: 0;
    transform: translateY(-20px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.feedback-header {
  display: flex;
  align-items: center;
  gap: 15px;
  margin-bottom: 20px;
}

.feedback-header.correct {
  color: #27ae60;
}

.feedback-header.incorrect {
  color: #e74c3c;
}

.feedback-icon {
  font-size: 2rem;
}

.feedback-title {
  font-size: 1.3rem;
  font-weight: 600;
}

.feedback-content {
  margin-bottom: 25px;
}

.correct-answer {
  margin-bottom: 15px;
  padding: 12px 16px;
  background: rgba(231, 76, 60, 0.1);
  border-radius: 8px;
  border-left: 4px solid #e74c3c;
}

.label {
  font-weight: 600;
  color: #2c3e50;
}

.answer {
  color: #e74c3c;
  font-weight: 500;
}

.explanation {
  padding: 12px 16px;
  background: rgba(59, 130, 246, 0.1);
  border-radius: 8px;
  border-left: 4px solid #3b82f6;
}

.text {
  color: #2c3e50;
  line-height: 1.5;
}

.feedback-actions {
  text-align: center;
}

.next-btn {
  padding: 12px 30px;
  border: none;
  border-radius: 25px;
  font-size: 1rem;
  font-weight: 600;
  background: linear-gradient(135deg, #1e3a8a 0%, #3b82f6 100%);
  color: white;
  cursor: pointer;
  transition: all 0.3s ease;
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.next-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 20px rgba(30, 58, 138, 0.3);
}

/* 完成页面 */
.completion-section {
  position: relative;
  z-index: 1;
}

.completion-card {
  max-width: 600px;
  margin: 0 auto;
  text-align: center;
  animation: zoomIn 0.8s ease-out;
}

@keyframes zoomIn {
  from {
    opacity: 0;
    transform: scale(0.8);
  }
  to {
    opacity: 1;
    transform: scale(1);
  }
}

.completion-header {
  margin-bottom: 30px;
}

.completion-icon {
  font-size: 4rem;
  margin-bottom: 15px;
}

.completion-title {
  font-size: 2rem;
  color: #2c3e50;
  margin: 0 0 10px 0;
  font-weight: 700;
}

.completion-subtitle {
  font-size: 1.1rem;
  color: #7f8c8d;
  margin: 0;
}

.completion-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 20px;
  margin-bottom: 40px;
}

.stat-card {
  display: flex;
  align-items: center;
  gap: 15px;
  padding: 20px;
  background: linear-gradient(135deg, #f8f9fa 0%, #e9ecef 100%);
  border-radius: 15px;
  border: 1px solid rgba(0, 0, 0, 0.05);
}

.stat-icon {
  font-size: 1.5rem;
}

.stat-content {
  text-align: left;
}

.stat-value {
  font-size: 1.5rem;
  font-weight: 700;
  color: #3b82f6;
}

.stat-label {
  font-size: 0.8rem;
  color: #7f8c8d;
}

.completion-actions {
  display: flex;
  gap: 15px;
  justify-content: center;
  flex-wrap: wrap;
}

.primary-btn,
.secondary-btn {
  padding: 15px 30px;
  border: none;
  border-radius: 25px;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.3s ease;
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.primary-btn {
  background: linear-gradient(135deg, #1e3a8a 0%, #3b82f6 100%);
  color: white;
}

.primary-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 20px rgba(30, 58, 138, 0.3);
}

.secondary-btn {
  background: linear-gradient(135deg, #f8f9fa 0%, #e9ecef 100%);
  color: #2c3e50;
  border: 2px solid #e9ecef;
}

.secondary-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.1);
}

/* 卡片基础样式 */
.glass-card {
  background: white;
  border-radius: 20px;
  padding: 30px;
  box-shadow: 0 8px 25px rgba(0, 0, 0, 0.1);
  border: 1px solid rgba(0, 0, 0, 0.05);
  transition: all 0.3s ease;
  margin-bottom: 20px;
}

/* 智能推荐模式头部 */
.quick-mode-header {
  margin-bottom: 30px;
}

.quick-header-card {
  display: flex;
  align-items: center;
  padding: 25px 30px;
  background: linear-gradient(135deg, #f8f9fa 0%, #e9ecef 100%);
  border-radius: 20px;
  box-shadow: 0 8px 25px rgba(0, 0, 0, 0.1);
  border: 1px solid rgba(0, 0, 0, 0.05);
}

.quick-header-content {
  display: flex;
  align-items: center;
  gap: 15px;
}

.quick-header-icon {
  font-size: 2.5rem;
  color: #3b82f6;
}

.quick-header-info {
  text-align: left;
}

.quick-header-title {
  font-size: 1.5rem;
  color: #2c3e50;
  margin: 0 0 5px 0;
  font-weight: 600;
}

.quick-header-subtitle {
  font-size: 0.9rem;
  color: #7f8c8d;
  margin: 0 0 10px 0;
}

.quick-header-desc {
  font-size: 0.8rem;
  color: #856404;
  line-height: 1.4;
}

/* 快速完成页面样式 */
.quick-completion-stats {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 20px;
  margin-bottom: 40px;
}

.quick-stat-card {
  display: flex;
  align-items: center;
  gap: 15px;
  padding: 20px;
  background: linear-gradient(135deg, #f8f9fa 0%, #e9ecef 100%);
  border-radius: 15px;
  border: 1px solid rgba(0, 0, 0, 0.05);
}

.quick-stat-icon {
  font-size: 1.5rem;
}

.quick-stat-content {
  text-align: left;
}

.quick-stat-value {
  font-size: 1.5rem;
  font-weight: 700;
  color: #3b82f6;
}

.quick-stat-label {
  font-size: 0.8rem;
  color: #7f8c8d;
}

/* 响应式设计 */
@media (max-width: 768px) {
  .progress-header {
    flex-direction: column;
    gap: 15px;
    text-align: center;
  }

  .progress-stats {
    justify-content: center;
  }

  .question-header {
    flex-direction: column;
    gap: 10px;
    text-align: center;
  }

  .boolean-container {
    flex-direction: column;
  }

  .completion-stats {
    grid-template-columns: 1fr;
  }

  .quick-completion-stats {
    grid-template-columns: 1fr;
  }

  .completion-actions {
    flex-direction: column;
    align-items: center;
  }

  .primary-btn,
  .secondary-btn {
    width: 100%;
    max-width: 300px;
    justify-content: center;
  }

  .answer-header {
    flex-direction: column;
    gap: 10px;
    text-align: center;
  }

  .answer-textarea {
    min-height: 150px;
    padding: 15px;
  }
}

@media (max-width: 480px) {
  .progress-stats {
    flex-direction: column;
    gap: 10px;
  }

  .option-item {
    padding: 12px 15px;
  }

  .option-marker {
    width: 25px;
    height: 25px;
    font-size: 0.8rem;
  }

  .submit-btn {
    padding: 12px 30px;
    font-size: 1rem;
  }

  .next-btn {
    padding: 10px 25px;
    font-size: 0.9rem;
  }

  .primary-btn,
  .secondary-btn {
    padding: 12px 25px;
    font-size: 0.9rem;
  }

  .answer-textarea {
    min-height: 120px;
    padding: 12px;
    font-size: 0.9rem;
  }

  .answer-header {
    padding: 12px 15px;
  }

}

/* 结束学习确认对话框样式 */
.finish-confirm-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  animation: fadeIn 0.3s ease-out;
}

@keyframes fadeIn {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

.finish-confirm-dialog {
  background: white;
  border-radius: 20px;
  padding: 30px;
  max-width: 500px;
  width: 90%;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
  animation: slideInUp 0.4s ease-out;
}

@keyframes slideInUp {
  from {
    opacity: 0;
    transform: translateY(30px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.confirm-header {
  text-align: center;
  margin-bottom: 25px;
}

.confirm-icon {
  font-size: 3rem;
  margin-bottom: 15px;
  display: block;
}

.confirm-title {
  font-size: 1.5rem;
  color: #2c3e50;
  margin: 0;
  font-weight: 600;
}

.confirm-content {
  margin-bottom: 25px;
}

.confirm-content p {
  font-size: 1rem;
  color: #34495e;
  line-height: 1.6;
  margin: 0 0 20px 0;
  text-align: center;
}

.confirm-stats {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 15px;
  margin-top: 20px;
}

.confirm-stat {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 15px;
  background: linear-gradient(135deg, #f8f9fa 0%, #e9ecef 100%);
  border-radius: 12px;
  border: 1px solid rgba(0, 0, 0, 0.05);
}

.confirm-stat .stat-label {
  font-size: 0.8rem;
  color: #7f8c8d;
  margin-bottom: 5px;
}

.confirm-stat .stat-value {
  font-size: 1.2rem;
  font-weight: 700;
  color: #3b82f6;
}

.confirm-actions {
  display: flex;
  gap: 15px;
  justify-content: center;
  flex-wrap: wrap;
}

.confirm-actions .primary-btn,
.confirm-actions .secondary-btn {
  min-width: 120px;
}

/* 响应式设计 */
@media (max-width: 480px) {
  .finish-confirm-dialog {
    padding: 20px;
    margin: 20px;
  }
  
  .confirm-stats {
    grid-template-columns: 1fr;
  }
  
  .confirm-actions {
    flex-direction: column;
    align-items: center;
  }
  
  .confirm-actions .primary-btn,
  .confirm-actions .secondary-btn {
    width: 100%;
    max-width: 200px;
  }
}
</style>
